package org.example;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.util.Arrays;

public class OneToManyExample {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(Util.PERSISTENCE_UNIT);
        EntityManager em = emf.createEntityManager();
        OneToManyB oneToManyB1 = new OneToManyB();
        oneToManyB1.setStr("testStringB1");
        OneToManyB oneToManyB2 = new OneToManyB();
        oneToManyB2.setStr("testStringB2");

        OneToManyA oneToManyA = new OneToManyA();
        oneToManyA.setOneToManyBS(Arrays.asList(oneToManyB1,oneToManyB2));
        em.getTransaction().begin();
        em.persist(oneToManyA);
        em.persist(oneToManyB1);
        em.persist(oneToManyB2);
        em.getTransaction().commit();
        em.close();
    }
}
